package cn.sccdlg.spring5.ui;

import cn.sccdlg.spring5.service.AccountService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author RaoShuang
 * @emil 991207823@qq.com
 * @date 2020/10/17 22:15
 * 模拟一个表现层，用于调用业务层
 *  本次探究的是：spring如何管理bean对象之一 bean的创建和作用范围
 */
public class Client {

    /**
     * @param args
     */
    public static void main(String[] args) {
        //1.获取核心容器对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");

        //2.根据id获取Bean对象
        //2-1、默认无参构造器创建bean
//        AccountService as  = (AccountService)ac.getBean("accountService1");
//        as.saveAccount();

        //2-2、普通工厂模式创建bean
//        AccountService as2  = (AccountService)ac.getBean("accountService2");
//        as2.saveAccount();

        //2-3、静态工厂模式创建bean
//        AccountService as3  = (AccountService)ac.getBean("accountService3");
//        as3.saveAccount();

        //2-4、bean的作用范围：单例还是多例
        for (int i = 0; i < 3; i++) {
            AccountService as4  = (AccountService)ac.getBean("accountService4");
            System.out.println(as4);
        }
        System.out.println("*************分割线***********");
        for (int i = 0; i < 3; i++) {
            AccountService as5  = (AccountService)ac.getBean("accountService5");
            System.out.println(as5);
        }

    }

}
